<template>
    <div>
        <!--新增按钮-->
        <el-button type="primary" @click="addCourseVisible= true" style="margin: 10px" >申请新增</el-button>
        <!--      this.addForm.teacher=this.userInfo.name-->
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="我的已有课程" name="first"></el-tab-pane>
            <el-tab-pane label="新增课程申请" name="second"></el-tab-pane>
            <el-tab-pane label="修改课程申请" name="third"></el-tab-pane>
            <el-tab-pane label="删除课程申请" name="fourth"></el-tab-pane>
        </el-tabs>
        <!--新增对话框-->
        <el-dialog
                title="请输入新增课程信息"
                :visible.sync="addCourseVisible"
                width="600px"
                @closed="resetAddForm('addForm')">
            <!--申请表单-->
            <el-form :model="addForm" :rules="addRules" ref="addForm">
                <el-form-item label="课程名称" prop="courseName" label-width="100px">
                    <el-input v-model="addForm.courseName" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="课程编号" prop="courseId" label-width="100px">
                    <el-input v-model="addForm.courseId" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="开课院系" prop="school" label-width="100px">
                    <el-select v-model="addForm.school" placeholder="请选择"
                               @change="getMajorByCollege(addForm.school)">
                        <el-option
                                v-for="COLLEGE in collegeData"
                                :key="COLLEGE.id"
                                :label="COLLEGE.college"
                                :value="COLLEGE.college"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="授课专业" prop="major" label-width="100px">
                    <el-select v-model="addForm.major" placeholder="请选择" clearable filterable>
                        <el-option
                                v-for="item in majorData"
                                :key="item.id"
                                :label="item.major"
                                :value="item.id"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="授课教师" prop="teacher" label-width="100px">
                    <el-input v-model="addForm.teacher" disabled></el-input>
                </el-form-item>
                <el-form-item label="授课教师工号" prop="teacherId" label-width="100px">
                    <el-input v-model="addForm.teacherId" disabled></el-input>
                </el-form-item>
                <el-form-item label="学分" prop="credit" label-width="100px">
                    <el-input v-model="addForm.credit" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="学时" prop="hour" label-width="100px">
                    <el-input v-model="addForm.hour" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="选课容量" prop="volume" label-width="100px">
                    <el-input v-model="addForm.volume" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="授课时间" prop="timeId" label-width="100px">
                    <el-select v-model="addForm.timeId" multiple placeholder="请选择上课时间" clearable filterable>
                        <el-option
                                v-for="item in timeData"
                                :key="item.id"
                                :label="item.show"
                                :value="item.id"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="授课教室" prop="location" label-width="100px">
                    <el-select v-model="addForm.location" placeholder="请选择" clearable filterable>
                        <el-option
                                v-for="item in locationData"
                                :key="item.id"
                                :label="item.courseLocation"
                                :value="item.id"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="课程简介" prop="intro" label-width="100px">
                    <el-input v-model="addForm.intro" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>
            <!--按钮-->
            <div slot="footer" class="dialog-footer">
                <el-button @click="resetAddForm('addForm')">取 消</el-button>
                <el-button type="primary" @click="submitAddForm('addForm')">提交</el-button>
            </div>
        </el-dialog>
        <!--删除对话框-->
        <el-dialog
                title="请输入课程信息"
                :visible.sync="deleteCourseVisible"
                width="600px"
                @closed="resetDeleteForm('deleteForm')">
            <!--申请表单-->
            <el-form :model="deleteForm" :rules="deleteRules" ref="deleteForm">
                <el-form-item label="课程id" prop="id" label-width="100px">
                    <el-input v-model="deleteForm.id" disabled></el-input>
                </el-form-item>
                <el-form-item label="课程名称" prop="courseName" label-width="100px">
                    <el-input v-model="deleteForm.courseName" disabled autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="课程编号" prop="courseId" label-width="100px">
                    <el-input v-model="deleteForm.courseId" disabled autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="开课院系" prop="school" label-width="100px">
                    <el-input v-model="deleteForm.school" disabled></el-input>
                </el-form-item>
                <el-form-item label="授课专业" prop="major" label-width="100px">
                    <el-input v-model="deleteForm.major" disabled></el-input>
                </el-form-item>
                <el-form-item label="授课教师" prop="teacher" label-width="100px">
                    <el-input v-model="deleteForm.teacher" disabled></el-input>
                </el-form-item>
                <el-form-item label="授课教师id" prop="teacherId" label-width="100px">
                    <el-input v-model="deleteForm.teacherId" disabled></el-input>
                </el-form-item>
                <el-form-item label="学分" prop="credit" label-width="100px">
                    <el-input v-model="deleteForm.credit" disabled autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="学时" prop="hour" label-width="100px">
                    <el-input v-model="deleteForm.hour" disabled autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="选课容量" prop="volume" label-width="100px">
                    <el-input v-model="deleteForm.volume" disabled autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="授课时间" prop="timeId" label-width="100px">
                    <el-input v-model="deleteForm.timeId" disabled autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="授课教室" prop="location" label-width="100px">
                    <el-input v-model="deleteForm.location" disabled autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="课程简介" prop="intro" label-width="100px">
                    <el-input v-model="deleteForm.intro" disabled autocomplete="off"></el-input>
                </el-form-item>
            </el-form>
            <!--按钮-->
            <div slot="footer" class="dialog-footer">
                <el-button @click="resetDeleteForm('deleteForm')">取 消</el-button>
                <el-button type="primary" @click="submitDeleteForm('deleteForm')">删除</el-button>
            </div>
        </el-dialog>
        <!--编辑对话框-->
        <el-dialog
                title="请输入课程信息"
                :visible.sync="editCourseVisible"
                width="600px"
                @closed="resetEditForm('editForm')">
            <!--申请表单-->
            <el-form :model="editForm" :rules="editRules" ref="editForm">
                <el-form-item label="课程id" prop="id" label-width="100px">
                    <el-input v-model="editForm.id" disabled></el-input>
                </el-form-item>
                <el-form-item label="课程名称" prop="courseName" label-width="100px">
                    <el-input v-model="editForm.courseName" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="课程编号" prop="courseId" label-width="100px">
                    <el-input v-model="editForm.courseId" disabled autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="开课院系" prop="school" label-width="100px">
                    <el-input v-model="editForm.school" disabled></el-input>
                </el-form-item>
                <el-form-item label="授课专业" prop="major" label-width="100px">
                    <el-input v-model="editForm.major" disabled></el-input>
                </el-form-item>
                <el-form-item label="授课教师" prop="teacher" label-width="100px">
                    <el-input v-model="editForm.teacher" disabled></el-input>
                </el-form-item>
                <el-form-item label="授课教师id" prop="teacherId" label-width="100px">
                    <el-input v-model="editForm.teacherId" disabled></el-input>
                </el-form-item>
                <el-form-item label="学分" prop="credit" label-width="100px">
                    <el-input v-model="editForm.credit" disabled autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="学时" prop="hour" label-width="100px">
                    <el-input v-model="editForm.hour" disabled autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="选课容量" prop="volume" label-width="100px">
                    <el-input v-model="editForm.volume" autocomplete="off" @input="change($event)" ></el-input>
                </el-form-item>
                <el-form-item label="授课时间" prop="time" label-width="100px">
                    <el-select v-model="editForm.time" multiple placeholder="请选择上课时间" @input="change($event)" clearable filterable>
                        <el-option
                                v-for="item in timeData"
                                :key="item.id"
                                :label="item.show"
                                :value="item.id"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="授课教室" prop="location" label-width="100px">
                    <el-select v-model="editForm.location" placeholder="请选择" @input="change($event)" clearable filterable>
                        <el-option
                                v-for="item in locationData"
                                :key="item.id"
                                :label="item.courseLocation"
                                :value="item.id"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="课程简介" prop="intro" label-width="100px">
                    <el-input v-model="editForm.intro" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>
            <!--按钮-->
            <div slot="footer" class="dialog-footer">
                <el-button @click="resetEditForm('editForm')">取消</el-button>
                <el-button type="primary" @click="submitEditForm('editForm')">提交</el-button>
            </div>
        </el-dialog>

        <div v-if="tabName==='first'">
            <h3>我的已有课程</h3>
            <el-table title="教师已有课程"
                      ref="courseTable" :data="courseData" border stripe style="width: fit-content; margin-left: 10px">
                <el-table-column
                        prop="id"
                        label="课程id"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="semester"
                        label="开课学期"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="courseId"
                        label="课程编号"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="courseName"
                        label="课程名称"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="schoolName"
                        label="授课学院"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="major"
                        label="授课专业"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="credit"
                        label="学分"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="hour"
                        label="学时"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="time"
                        label="上课时间"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="location"
                        label="上课地点"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="teacher"
                        label="教师"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="teacherId"
                        label="教师id"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="volume"
                        label="选课容量"
                        width=80>
                </el-table-column>
                <el-table-column
                        prop="intro"
                        label="课程简介"
                        width="140">
                </el-table-column>

                <el-table-column
                        fixed="right"
                        label="操作"
                        width="100">
                    <template slot-scope="scope">
                        <el-button @click="deleteCourseHandle(scope.row.id)" type="text">删除</el-button>
                        <el-button @click="editCourseHandle(scope.row.id)" type="text">编辑</el-button>

                    </template>
                </el-table-column>

            </el-table>
        </div>

        <div v-if="tabName==='second'">
            <h3>待审核[新增课程]申请列表</h3>
            <el-table title="待审核[新增课程]申请列表"
                      ref="addTable" :data="addData" border stripe
                      style="width: fit-content; margin-left: 10px">
                <el-table-column
                        prop="id"
                        label="申请序号"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="courseId"
                        label="课程编号"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="courseName"
                        label="课程名称"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="teacher"
                        label="申请教师"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="teacherId"
                        label="申请教师工号"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="school"
                        label="授课学院"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="major"
                        label="授课专业"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="credit"
                        label="学分"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="hour"
                        label="学时"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="time"
                        label="上课时间"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="location"
                        label="上课地点"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="volume"
                        label="选课容量"
                        width=100>
                </el-table-column>
                <el-table-column
                        prop="intro"
                        label="课程简介"
                        width="140">
                </el-table-column>
            </el-table>
        </div>

        <div v-if="tabName==='third'">
            <h3>待审核[修改课程]申请列表</h3>
            <el-table title="待审核[新增课程]申请列表"
                      ref="editTable"
                      :data="editData"
                      border
                      stripe
                      style="width: fit-content; margin-left: 10px">
                <el-table-column
                        prop="id"
                        label="申请序号"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="target"
                        label="课程id"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="courseId"
                        label="课程编号"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="courseName"
                        label="课程名称"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="school"
                        label="授课学院"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="major"
                        label="授课专业"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="credit"
                        label="学分"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="hour"
                        label="学时"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="timeId"
                        abel="上课时间"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="location"
                        label="上课地点"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="teacher"
                        label="申请教师"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="teacherId"
                        label="申请教师工号"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="volume"
                        label="选课容量"
                        width=100>
                </el-table-column>
                <el-table-column
                        prop="intro"
                        label="课程简介"
                        width="140">
                </el-table-column>
            </el-table>
        </div>

        <div v-if="tabName==='fourth'">
            <h3>待审核[删除课程]申请列表</h3>
            <el-table title="待审核[删除课程]申请列表"
                      ref="deleteTable"
                      :data="deleteData"
                      border
                      stripe
                      style="width: fit-content; margin-left: 10px">
                <el-table-column
                        prop="id"
                        label="申请序号"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="target"
                        label="课程id"
                        width="80">
                </el-table-column>
                <el-table-column
                        prop="courseId"
                        label="课程编号"
                        width="140">
                </el-table-column>
                <el-table-column
                        prop="courseName"
                        label="课程名称"
                        width="140">
                </el-table-column>
            </el-table>
        </div>

    </div>
</template>

<script>
    // import qs from 'qs'
    export default {
        name: "TeaCourse",
        data() {

            return {
                teaId:"",
                //表格数据
                courseData:[],
                //新增课程
                addData: [],
                addForm: {},
                addRules: {
                    courseName: [
                        {required: true, message: '请输入课程名称', trigger: 'blur'},
                        // {pattern: /^[\u4E00-\u9FA5A-Za-z0-9]+$/, message: "课程名称是中英文", trigger: "blur"}
                    ],
                    courseId: [
                        {required: true, message: '请输入课程编码', trigger: 'blur'},
                        {pattern: /^[0-9]*$/, message: "教室编码是数字", trigger: "blur"}
                    ],
                    school: [
                        {required: true, message: '请选择开课院系', trigger: 'blur'},
                    ],
                    credit: [
                        {required: true, message: '请输入课程学分', trigger: 'blur'},
                        {pattern: /^[1-9]\d*$/, message: "学分是正整数", trigger: "blur"}
                    ],
                    hour: [
                        {required: true, message: '请输入课程学时', trigger: 'blur'},
                        {pattern: /^[1-9]\d*$/, message: "学时是正整数", trigger: "blur"}
                    ],
                    major: [
                        {required: true, message: '请选择授课专业', trigger: 'blur'},
                        {pattern: /^[\u4E00-\u9FA5A-Za-z0-9]+$/, message: "专业名是中英文", trigger: "blur"}
                    ],
                    teacher: [
                        {required: true, message: '请输入教师姓名', trigger: 'blur'},
                        {pattern: /^[\u4E00-\u9FA5A-Za-z0-9]+$/, message: "教师姓名是中英文", trigger: "blur"}
                    ],
                    teacherId: [
                        {required: true, message: '请输入教师工号', trigger: 'blur'},
                    ],
                    intro: [],
                    volume: [
                        {required: true, message: '请输入最大选课人数', trigger: 'blur'},
                        {pattern: /^[1-9]\d*$/, message: "最大选课人数需是正整数", trigger: "blur"}
                    ],
                    timeId: [
                        {required: true, message: '请输入上课时间', trigger: 'blur'},
                        // {pattern: /^([A-Z]+[0-9]*)+$/, message: "用逗号分割数字", trigger: "blur"}
                    ],
                    location: [
                        {required: true, message: '请输入授课教室', trigger: 'blur'},
                    ],
                },
                deleteRules:{},
                editRules:{
                    courseId: [
                        {required: true, message: '请输入课程编号', trigger: 'blur'},
                    ],
                    courseName: [
                        {required: true, message: '请输入课程名称', trigger: 'blur'},
                    ],
                    school:[
                        {required: true, message: '请输入授课学院', trigger: 'blur'},
                    ],
                    major:[
                        {required: true, message: '请输入授课专业', trigger: 'blur'},
                    ],
                    credit:[
                        {required: true, message: '请输入学分', trigger: 'blur'},
                    ],
                    hour:[
                        {required: true, message: '请输入学时', trigger: 'blur'},
                    ],
                    timeId:[
                        {required: true, message: '请输入上课时间', trigger: 'blur'},
                    ],
                    location:[
                        {required: true, message: '请输入上课地点', trigger: 'blur'},
                    ],
                    volume:[
                        {required: true, message: '请输入选课容量', trigger: 'blur'},
                    ],
                    intro:[
                        {required: false, message: '请输入课程简介', trigger: 'blur'},
                    ]

                },

                //修改课程
                editData: [],
                editForm:{},

                //删除课程
                deleteData: [],
                deleteForm:{},

                collegeData:[],
                majorData:[],
                locationData:[],
                timeData:[],

                addCourseVisible: false,
                editCourseVisible: false,
                deleteCourseVisible:false,

                //标签页相关
                activeName: 'first',//初始亮着的页面
                tabName: 'first',
            }
        },
        created(){
            this.getUserInfo();
            this.getTeaCourseList();
            this.getCollegeList();
            this.getLocationList();
            // this.getAddList();
            // this.getEditList();
            // this.getDeleteList();
            this.getTimeList();
        },
        methods:{
            // 获取用户信息
            getUserInfo() {
                this.$axios.get("/sys/userInfo").then(res => {
                    // console.log(res.data.data);
                    this.addForm.teacher = res.data.data.name;
                    this.addForm.teacherId = res.data.data.username;
                })
            },
            //获取院系列表
            getCollegeList() {
                this.$axios.get('/sys/college/list').then(res => {
                    this.collegeData = res.data.data
                })
            },
            //根据之前选择的院系返回专业
            getMajorByCollege(college) {
                // console.log(college)
                this.$axios.post('/sys/major/listByCollege?', {id: college}).then(res => {
                    // alert("选择了新的院系，现在在选择专业")
                    // console.log(res.data.data)
                    this.majorData = res.data.data
                })
            },
            //获得时间表
            getTimeList(){
                this.$axios.get("/sys/time/listAll").then(res => {
                    // console.log(res.data.data)
                    this.timeData = res.data.data;
                })
            },
            //获得教室列表
            getLocationList(){
                this.$axios.get("/sys/location/list").then(res => {
                    // console.log(res.data.data)
                    this.locationData = res.data.data;
                })
            },
            //获得教师已有列表
            getTeaCourseList(){
                this.$axios.get("/sys/userInfo").then(res1 => {
                    this.userInfo = res1.data.data;
                    this.$axios.post("/sys/course/list/teacher",{teacherId:this.userInfo.username}).then(res => {
                        var newData=[]
                        // console.log("msg:",res.data.data);
                        for (var i=0;i<res.data.data.length;i++) {
                            if ((res.data.data[i].statu === 0)) {
                                var data = {}
                                var mapTime = [], mapSemester = [], mapLocation = [], mapMajor = []
                                data.id = res.data.data[i].id

                                for (var key in res.data.data[i].semester) {
                                    mapSemester.push(res.data.data[i].semester[key])
                                    mapSemester.push(',')
                                }
                                mapSemester.pop()
                                data.semester = mapSemester

                                data.courseId = res.data.data[i].courseId
                                data.courseName = res.data.data[i].courseName
                                if (res.data.data[i].type === 0) {
                                    data.type = '通选课程'
                                } else {
                                    if (res.data.data[i].type === 1)
                                        data.type = '专选课程'
                                }

                                //得到数据时直接得到schoolName
                                data.schoolName = res.data.data[i].schoolName

                                for (var key in res.data.data[i].major) {
                                    mapMajor.push(res.data.data[i].major[key])
                                    mapMajor.push(',')
                                }
                                mapMajor.pop()
                                data.major = mapMajor

                                data.credit = res.data.data[i].credit
                                data.hour = res.data.data[i].hour

                                for (var key in res.data.data[i].time) {
                                    mapTime.push(res.data.data[i].time[key])
                                    mapTime.push(',')
                                }
                                mapTime.pop()
                                data.time = mapTime

                                // for (var key in res.data.data[i].location){
                                //     mapLocation.push(res.data.data[i].location[key])
                                //     mapLocation.push(',')
                                // }
                                // mapLocation.pop()
                                // data.location = mapLocation
                                if (res.data.data[i].location !== null) {
                                    data.location = res.data.data[i].location.courseLocation
                                }

                                data.teacher = res.data.data[i].teacher
                                data.teacherId = res.data.data[i].teacherId
                                data.intro = res.data.data[i].intro
                                data.volume = res.data.data[i].volume
                                data.currentNum = res.data.data[i].currentNum

                                newData.push(data)
                                // console.log("教师课程信息",data);
                            }
                            this.courseData = newData
                        }
                    })
                })
            },
            // //获得待审核的新增课程申请列表
            getAddList(){
                this.$axios.get('sys/course/apply/save/list').then(res => {
                    // console.log("新增申请：",res.data.data)
                    // this.addData = res.data.data
                    this.$axios.post("/sys/course/list/teacher",{teacherId:this.userInfo.username}).then(res => {
                        var newData=[]
                        // console.log("msg:",res.data.data);
                        for (var i=0;i<res.data.data.length;i++) {
                            if ((res.data.data[i].statu === 1)) {
                                var data = {}
                                var mapTime = [], mapSemester = [], mapLocation = [], mapMajor = []
                                data.id = res.data.data[i].id

                                for (var key in res.data.data[i].semester) {
                                    mapSemester.push(res.data.data[i].semester[key])
                                    mapSemester.push(',')
                                }
                                mapSemester.pop()
                                data.semester = mapSemester

                                data.courseId = res.data.data[i].courseId
                                data.courseName = res.data.data[i].courseName
                                if (res.data.data[i].type === 0) {
                                    data.type = '通选课程'
                                } else {
                                    if (res.data.data[i].type === 1)
                                        data.type = '专选课程'
                                }

                                //得到数据时直接得到schoolName
                                data.schoolName = res.data.data[i].schoolName

                                for (var key in res.data.data[i].major) {
                                    mapMajor.push(res.data.data[i].major[key])
                                    mapMajor.push(',')
                                }
                                mapMajor.pop()
                                data.major = mapMajor

                                data.credit = res.data.data[i].credit
                                data.hour = res.data.data[i].hour

                                for (var key in res.data.data[i].time) {
                                    mapTime.push(res.data.data[i].time[key])
                                    mapTime.push(',')
                                }
                                mapTime.pop()
                                data.time = mapTime

                                // for (var key in res.data.data[i].location){
                                //     mapLocation.push(res.data.data[i].location[key])
                                //     mapLocation.push(',')
                                // }
                                // mapLocation.pop()
                                // data.location = mapLocation
                                if (res.data.data[i].location !== null) {
                                    data.location = res.data.data[i].location.courseLocation
                                }

                                data.teacher = res.data.data[i].teacher
                                data.teacherId = res.data.data[i].teacherId
                                data.intro = res.data.data[i].intro
                                data.volume = res.data.data[i].volume
                                data.currentNum = res.data.data[i].currentNum

                                newData.push(data)
                                // console.log("教师课程信息",data);
                            }
                            this.addData = newData
                        }
                    })
                })
            },
            // //获得待审核的修改课程申请列表
            // getEditList(){
            //   this.$axios.get('sys/course/apply/update/list').then(res => {
            //     this.editData = res.data.data
            //   })
            // },
            // //获得待审核的删除课程申请列表
            // getDeleteList(){
            //   this.$axios.get('sys/course/apply/delete/list').then(res => {
            //       // console.log("删除申请：",res.data.data)
            //     this.deleteData = res.data.data
            //   })
            // },
            //重设新增表单
            resetAddForm(formName){
                this.$refs[formName].resetFields();
                this.addForm = {}
                this.addCourseVisible = false
            },
            resetDeleteForm(formName){
                this.$refs[formName].resetFields();
                this.addForm = {}
                this.deleteCourseVisible = false
            },
            resetEditForm(formName){
                this.$refs[formName].resetFields();
                this.addForm = {}
                this.editCourseVisible = false
            },

            //提交新增课程表单
            submitAddForm(formName) {
                const timeli=this.addForm.timeId.join(",")
                // console.log('1')
                // console.log(timeli)
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.$axios({
                            method:'POST',
                            url:'sys/course/apply/save',
                            data: {
                                courseName: this.addForm.courseName,
                                courseId: this.addForm.courseId,
                                school: this.addForm.school,
                                major: this.addForm.major,
                                teacher: this.addForm.teacher,
                                teacherId: this.addForm.teacherId,
                                credit: this.addForm.credit,
                                hour: this.addForm.credit,
                                volume: this.addForm.volume,
                                timeId: timeli,
                                location: this.addForm.location,
                                intro: this.addForm.intro
                            },
                        }).then(res => {
                            // console.log(res.data)
                            this.resetAddForm(formName)
                            this.$message({
                                showClose: true,
                                message: '恭喜你，申请成功',
                                type: 'success',
                                onClose: () => {
                                    this.getAddList();
                                }
                            });
                            this.addCourseVisible = false;
                        })
                    } else {
                        // console.log('error submit!');
                        return false;
                    }
                });
            },

            //点击删除按钮
            deleteCourseHandle(id){
                this.$axios.post("/sys/course/info?", {id: id}).then(res => {
                    this.deleteForm = res.data.data

                    this.deleteCourseVisible = true
                })
            },

            //提交删除课程表单
            submitDeleteForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.$axios.post('sys/course/apply/delete' ,this.deleteForm)
                            .then(res => {
                                // console.log(res.data)
                                this.resetDeleteForm(formName)
                                this.$message({
                                    showClose: true,
                                    message: '恭喜你，申请成功',
                                    type: 'success',
                                    onClose: () => {
                                        this.getTeaCourseList();
                                        this.getDeleteList();
                                    }
                                });
                            })
                    } else {
                        // console.log('error submit!');
                        return false;
                    }
                });
            },

            //  点击编辑按钮
            editCourseHandle(id){
                this.$axios.post("/sys/course/info?", {id: id}).then(res => {
                    // this.editForm = res.data.data
                    var mapTime=[],mapSemester=[],mapMajor=[]
                    this.editForm.id = res.data.data.id

                    for (var key in res.data.data.semester){
                        mapSemester.push(res.data.data.semester[key])
                    }
                    this.editForm.semester=mapSemester

                    this.editForm.courseId = res.data.data.courseId
                    this.editForm.courseName = res.data.data.courseName
                    if(res.data.data.type===0){
                        this.editForm.type='通选课程'
                    }
                    else {
                        if (res.data.data.type===1)
                            this.editForm.type='专选课程'
                    }

                    //得到数据时直接得到schoolName
                    this.editForm.schoolName = res.data.data.schoolName

                    for (var key in res.data.data.major){
                        mapMajor.push(res.data.data.major[key])
                    }
                    this.editForm.major = mapMajor

                    this.editForm.credit = res.data.data.credit
                    this.editForm.hour = res.data.data.hour

                    for (var key in res.data.data.time){
                        mapTime.push(res.data.data.time[key])
                    }
                    this.editForm.time=mapTime

                    // for (var key in res.data.data[i].location){
                    //     mapLocation.push(res.data.data[i].location[key])
                    //     mapLocation.push(',')
                    // }
                    // mapLocation.pop()
                    // data.location = mapLocation
                    if (res.data.data.location!==null) {
                        this.editForm.location = res.data.data.location.id
                    }
                    this.editForm.teacher = res.data.data.teacher
                    this.editForm.teacherId = res.data.data.teacherId
                    this.editForm.intro = res.data.data.intro
                    // this.editForm.volume = res.data.data.volume
                    this.editCourseVisible = true
                })
            },

            //提交编辑课程表单
            submitEditForm(formName) {
                const timeli=this.editForm.timeId.join(",")
                // console.log('1')
                // console.log(timeli)
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        const schoolItem=this.collegeData.find(item=>item.college===this.editForm.schoolName)
                        const schoolId=schoolItem.id
                        var typeId
                        if (this.editForm.type==="通选课程") typeId=0
                        else {
                            typeId=1
                        }

                        var majorList=new Array()
                        var semesterList=new Array()

                        this.$axios.post("/sys/course/info?",{id:this.editForm.id}).then(res1 => {
                            for (var key in res1.data.data.major){
                                majorList.push(key-0)
                            }
                            for (var key in res1.data.data.semester){
                                semesterList.push(key-0)
                            }
                        })
                        this.$axios({
                            method:'POST',
                            url: 'sys/course/apply/update',
                            data:{
                                id:this.editForm.id,
                                semesterId: semesterList,
                                courseId: this.editForm.courseId,
                                courseName: this.editForm.courseName,
                                type: typeId,
                                school: schoolId,
                                majorId: majorList,
                                credit: this.editForm.credit,
                                hour: this.editForm.hour,
                                timeId: this.editForm.time,
                                locationId: this.editForm.location,
                                teacher: this.editForm.teacher,
                                teacherId: this.editForm.teacherId,
                                intro: this.editForm.intro,
                                volume: this.editForm.volume
                            },
                        }).then(res => {
                            // console.log(res.data)
                            this.resetEditForm(formName)
                            this.$message({
                                showClose: true,
                                message: '恭喜你，操作成功',
                                type: 'success',
                                onClose: () => {
                                    this.getTeaCourseList();
                                    this.getEditList();
                                }
                            });
                        })
                    } else {
                        console.log('error submit!');
                        return false;
                    }
                });
            },


            //分标签页用的
            handleClick(tab, event) {
                this.tabName = tab.name;
            },
            change(e){
                this.$forceUpdate();
            },
        }
    }
</script>

<style scoped>

</style>